//
//  LKWorkOrderDetailViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/4/25.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKWorkOrderDetailViewController.h"
#import "LKWorkOrderListDetailCell.h"
#import "LKWorkOrderListDetailPictureCell.h"
#import "LKWorkOrderListDetailOnlyImageCell.h"
#import "LKWorkOrderDetailContractDetailCell.h"
#import "YLInvestmentTableViewCell.h"
#import "LKOrderRecordViewController.h"
@interface LKWorkOrderDetailViewController ()<UITableViewDataSource,UITableViewDelegate,UIImagePickerControllerDelegate,UIViewControllerTransitioningDelegate,UINavigationControllerDelegate>

@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)NSArray *headerTitlsArray;
@property(nonatomic,strong)NSArray *headerIconsArray;
@property(nonatomic,strong)NSMutableArray *cellContentArray;
@property(nonatomic,strong)NSMutableDictionary *indexPathDic;
@property(nonatomic,assign)BOOL productFlag;
@property(nonatomic,assign)BOOL bankFlag;
@property(nonatomic,assign)BOOL secondbankFlag;
@property(nonatomic,assign)BOOL contractHomeFlag;
@property(nonatomic,assign)BOOL contractDetailFlag;
@property(nonatomic,assign)BOOL POSFlag;
@property(nonatomic,assign)BOOL otherFlag;
@property(nonatomic,strong)UIImageView *currentImageView;
@end

@implementation LKWorkOrderDetailViewController

-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH , HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStyleGrouped registercellClasss:@[@"LKWorkOrderListDetailCell",@"LKWorkOrderListDetailPictureCell",@"LKWorkOrderListDetailOnlyImageCell",@"LKWorkOrderDetailContractDetailCell",@"YLInvestmentTableViewCell"]];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableview];
    self.navigationItem.title = self.model.contractCode;
    NSArray *arra;
//    if (self.addOrderModel) {
////        self.model = self.addOrderModel;
//        [self.tableview reloadData];
//    }else{
//        [self getOrderDetailInformaiton];
//    }
    [self getOrderDetailInformaiton];
//    self.model.contractCode
    
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:@"查看订单记录" forState:UIControlStateNormal];
    [btn setTitleColor:cellTextColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:10];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(lookAtOrderRecord:) forControlEvents:UIControlEventTouchUpInside];
}
/**
 查看订单记录
 
 */
-(void)lookAtOrderRecord:(UIButton *)btn{
    LKOrderRecordViewController *vc = [[LKOrderRecordViewController alloc] init];
    vc.orderCode = self.model.orderCode;
    [self.navigationController pushViewController:vc animated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.cellContentArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSArray *contentsArra = self.cellContentArray[section];
    return contentsArra.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKWorkOrderListDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWorkOrderListDetailCell"];
    cell.confirmImageView.hidden = YES;
//    NSArray *array = self.cellContentArray[indexPath.section];
    WS(weakSelf)
    if (indexPath.section != 4) {
           cell.titileLabel.text = self.cellContentArray[indexPath.section][indexPath.row];
    }else{
        
    }

    switch (indexPath.section) {
        case 0:
        {
            cell.arrowBtn.hidden = YES;
            cell.lineView.hidden = YES;
            if (indexPath.row == 0) {
                cell.confirmImageView.hidden = NO;
                if ([self.model.cusIsAuthenticated boolValue]) {
                    cell.confirmImageView.image = [UIImage imageNamed:@"confirmPeople"];
                }else{
                    cell.confirmImageView.image = [UIImage imageNamed:@"unconfirmPeople"];
                }
                cell.lineView.hidden = NO;
            }
            if (indexPath.row == 5 || indexPath.row == 6) {
                LKWorkOrderListDetailPictureCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWorkOrderListDetailPictureCell"];
                cell.titleLabel.text = self.cellContentArray[indexPath.section][indexPath.row];
//                cell.pictureImageView.userInteractionEnabled = NO;
//                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
//
//                [cell.pictureImageView addGestureRecognizer:tap];
//                [tap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
//                    //             判断是否支持相机
//                    if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//                        [SVProgressHUD showInfoWithStatus:@"无法使用相机"];
//                        return;
//                    }
//                    self.currentImageView = (UIImageView *)x.view;
//                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//                    NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//                    [self camerOrAlbumsPhotoChooseWithAlert:alert AndSourceType:sourceType];
//                    [self presentViewController:alert animated:YES completion:nil];
//                }];
                if (indexPath.row == 5) {
                   cell.pitureUrl = [NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.identitfyPhotoUrl];
                    [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.identitfyPhotoUrl]] placeholderImage:[UIImage imageNamed:@"pic"]];
                }else{
                    cell.pitureUrl = [NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.identitfyBackPhotoUrl];
                    [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.identitfyBackPhotoUrl]] placeholderImage:[UIImage imageNamed:@"pic"]];
                }
                return cell;
            }
        }
            break;
        case 1:
        {
            cell.arrowBtn.hidden = YES;
            cell.lineView.hidden = YES;
            if (indexPath.row == 0) {
                cell.arrowBtn.hidden = NO;
                cell.lineView.hidden = NO;
                cell.arrowBtn.selected = _productFlag;

            }
            return cell;
           
        }
            break;
        case 2:
        {
            cell.arrowBtn.hidden = YES;
            cell.lineView.hidden = YES;
            if (indexPath.row == 0) {
                cell.lineView.hidden = NO;
                
            }
            return cell;
        }
            break;
        case 3:
        {
            cell.arrowBtn.hidden = YES;
            cell.lineView.hidden = YES;
            if (indexPath.row == 0) {
                cell.arrowBtn.hidden = NO;
                cell.lineView.hidden = NO;
                cell.arrowBtn.selected = _bankFlag;
                cell.confirmImageView.hidden = NO;
                if ([self.model.payIsAuthenticated boolValue]) {
                    cell.confirmImageView.image = [UIImage imageNamed:@"confirmBankCard"];
                }else{
                   cell.confirmImageView.image = [UIImage imageNamed:@"unconfirmBankCard"];
                }
            }
            if ([self.cellContentArray[indexPath.section][indexPath.row] containsString:@"回款账户"]) {
                cell.arrowBtn.hidden = NO;
                cell.lineView.hidden = NO;
                cell.arrowBtn.selected = self.secondbankFlag;
                cell.confirmImageView.hidden = NO;
                if ([self.model.repayIsAuthenticated boolValue]) {
                    cell.confirmImageView.image = [UIImage imageNamed:@"confirmBankCard"];
                }else{
                    cell.confirmImageView.image = [UIImage imageNamed:@"unconfirmBankCard"];
                }
            }
            if ([self.cellContentArray[indexPath.section][indexPath.row] containsString:@"银行卡正面复印件"]) {
                LKWorkOrderListDetailPictureCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWorkOrderListDetailPictureCell"];
                 NSArray *array = self.cellContentArray[indexPath.section];
                if (indexPath.row == array.count - 1) {
                    cell.pitureUrl = [NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.repayAccountPhotoUrl];
                    [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.repayAccountPhotoUrl]] placeholderImage:[UIImage imageNamed:@"pic"]];
                }else{
                    cell.pitureUrl = [NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.payAccountPhotoUrl];
                    [cell.pictureImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,self.model.payAccountPhotoUrl]] placeholderImage:[UIImage imageNamed:@"pic"]];
                }
                cell.titleLabel.text = self.cellContentArray[indexPath.section][indexPath.row];
                return cell;
            }
            return cell;
           
        }
            break;
        case 4:
        {
            YLInvestmentTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"YLInvestmentTableViewCell"];
            cell.model = self.cellContentArray[indexPath.section][indexPath.row];
            return cell;
        }
            break;
        case 5:
        {
            cell.arrowBtn.hidden = YES;
            cell.lineView.hidden = YES;
            if (indexPath.row == 0) {
                cell.lineView.hidden = NO;
            }
            return cell;
        }
            break;
        case 6:
        {
            cell.arrowBtn.hidden = NO;
            cell.lineView.hidden = NO;
            cell.arrowBtn.selected = NO;
            if (indexPath.row == 0) {
                if (_contractHomeFlag) {
                    static NSString *cellId = @"contracHomeId";
                    LKWorkOrderDetailContractDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                    if (cell == nil) {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"LKWorkOrderDetailContractDetailCell" owner:self options:nil] lastObject];
                    }
                    cell.typeTitle = @"合同首页";
                    cell.orderModel = self.model;
                    cell.arrorBtn.selected = YES;
                    return cell;
                }
                
            }
            if (indexPath.row == 1) {

                if (self.contractDetailFlag) {
                    static NSString *cellId = @"contracDetailId";
                    LKWorkOrderDetailContractDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                    if (cell == nil) {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"LKWorkOrderDetailContractDetailCell" owner:self options:nil] lastObject];
                    }
                    cell.typeTitle = @"合同详情";
                    cell.orderModel = self.model;
                    cell.arrorBtn.selected = YES;
                    return cell;
                }
            }
            if (indexPath.row == 2) {
                if (self.POSFlag) {
                    static NSString *cellId = @"contracPOSId";
                    LKWorkOrderDetailContractDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                    if (cell == nil) {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"LKWorkOrderDetailContractDetailCell" owner:self options:nil] lastObject];
                    }
                    cell.typeTitle = @"POS凭证";
                    cell.orderModel = self.model;
                    cell.arrorBtn.selected = YES;
                    return cell;
                }
            }
            if (indexPath.row == 3) {
                if (self.otherFlag) {
                    static NSString *cellId = @"contracOtherId";
                    LKWorkOrderDetailContractDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
                    if (cell == nil) {
                        cell = [[[NSBundle mainBundle] loadNibNamed:@"LKWorkOrderDetailContractDetailCell" owner:self options:nil] lastObject];
                    }
                    cell.typeTitle = @"其他";
                    cell.orderModel = self.model;
                    cell.arrorBtn.selected = YES;
                    return cell;
                }
            }

            return cell;
        }
            break;

        default:
            break;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
        {
            if (indexPath.row == 5 || indexPath.row == 6) {
                return 90;
            }
            return 35;
        }
            break;
        case 1:
        {
            if (self.productFlag) {
                return 30;
            }
            return 50;
        }
            break;
        case 2:
        {
            return 35;
        }
            break;
        case 3:
        {
            if ([self.cellContentArray[indexPath.section][indexPath.row] containsString:@"银行卡正面复印件"]) {
                return 90;
            }
            return 50;
        }
            break;
        case 4:
        {
            return 145;
        }
            break;
        case 5:
        {
            return 35;
        }
            break;
        case 6:
        {
            if (indexPath.row == 0) {
                if (_contractHomeFlag) {
                if (self.model.orderAttachs1.count % 3 == 0) {
                    return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs1.count / 3)+(self.model.orderAttachs1.count / 3) * 10 );
                }
                return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs1.count / 3 + 1)+(self.model.orderAttachs1.count / 3) * 10 );
                }
            }else if (indexPath.row == 1){
                if (self.contractDetailFlag) {
                    if (self.model.orderAttachs2.count % 3 == 0) {
                        return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs2.count / 3)+(self.model.orderAttachs3.count / 3) * 10 );
                    }
                return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs2.count / 3 + 1)+(self.model.orderAttachs2.count / 3) * 10 );
                }
            }else if (indexPath.row == 2){
                if (self.POSFlag) {
                    if (self.model.orderAttachs3.count % 3 == 0) {
                        return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs3.count / 3)+(self.model.orderAttachs3.count / 3) * 10 );
                    }
                return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs3.count / 3 + 1)+(self.model.orderAttachs3.count / 3) * 10 );
                }
            }else{
                if (self.otherFlag) {
                    if (self.model.orderAttachs0.count % 3 == 0) {
                        return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs0.count / 3)+(self.model.orderAttachs0.count / 3) * 10 );
                    }
                return 70 + ((WIDTH - 40)/3 * 65 / 95 * (self.model.orderAttachs0.count / 3 + 1)+(self.model.orderAttachs0.count / 3) * 10 );
                }
            }
            return 50;
        }
            break;
        default:
            break;
    }
    return 0;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //设置头视图
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = cellHeaderBgColor;
    UIView *headerBottomView = [[UIView alloc] init];
    headerBottomView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:headerBottomView];
    [headerBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(headerView);
        make.height.mas_equalTo(37);
    }];
    UIImageView *iconImageView = [[UIImageView alloc] init];
    iconImageView.image = [UIImage imageNamed:self.headerIconsArray[section]];
    [headerBottomView addSubview:iconImageView];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(headerBottomView).offset(14);
        make.centerY.equalTo(headerBottomView);
    }];
    LKBaseLabel *label = [LKBaseLabel labelWithFrame:CGRectZero text:@"" textColor:COLOR_HEX(0x565D66) font:[UIFont systemFontOfSize:15] textAlignment:NSTextAlignmentLeft backgroundColor:[UIColor whiteColor]];
    label.text = self.headerTitlsArray[section];
    [headerBottomView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(8);
        make.centerY.equalTo(iconImageView);
    }];
    if (section == 0) {
        UIView *headerTopView = [[UIView alloc] init];
        headerTopView.backgroundColor = [UIColor whiteColor];
        [headerView addSubview:headerTopView];
        [headerTopView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.equalTo(headerView);
            make.height.mas_equalTo(44);
        }];
        NSString *statuStr = [NSString backOrderStatusAccordingStatusType:[_model.approvalStatus integerValue]];
        LKBaseLabel *statuLabel = [LKBaseLabel labelWithFrame:CGRectZero text:statuStr textColor:COLOR_HEX(0x0E8205) font:[UIFont systemFontOfSize:15] textAlignment:NSTextAlignmentCenter backgroundColor:[UIColor whiteColor]];
        [headerTopView addSubview:statuLabel];
        [statuLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(headerTopView);
            make.top.equalTo(headerTopView).offset(5);
        }];
        LKBaseLabel *stLabel = [LKBaseLabel labelWithFrame:CGRectZero text:@"订单状态" textColor:COLOR_HEX(0x929292) font:[UIFont systemFontOfSize:10] textAlignment:NSTextAlignmentCenter backgroundColor:[UIColor whiteColor]];
        [headerTopView addSubview:stLabel];
        [stLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(headerTopView);
            make.bottom.equalTo(headerTopView).offset(-5);
        }];
    }
    return headerView;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = cellHeaderBgColor;
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return section == 0 ? 98:37;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 16;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.section) {
        case 0:
            {

            }
            break;
        case 1:
        {
            if (indexPath.row == 0) {
                LKWorkOrderListDetailCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                self.productFlag = !self.productFlag;
               cell.arrowBtn.selected = self.productFlag;
                //产品信息
                NSString *productName = [NSString stringWithFormat:@"%@%@",@"产品名称：",_model.productName];
                if (self.productFlag) {
                    NSString *productCode = [NSString stringWithFormat:@"%@%@",@"产品编号：",_model.productCode];
                    NSString *productType = [NSString stringWithFormat:@"%@%@",@"产品类型：",_model.productCategoryS];
                    NSString *productTerm = [NSString stringWithFormat:@"%@%@",@"产品期限：",_model.productTerm];
                    NSString *productDuiHuan = [NSString stringWithFormat:@"%@%@",@"兑换方式：",[self accordingDuiFuFangshiType:[_model.payCategory integerValue]]];
                    NSString *yearShouyi = [NSString stringWithFormat:@"%@%@",@"年化收益：",_model.productAnnualizedYield];
                    [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[productName,productCode,productType,productTerm,productDuiHuan,yearShouyi]];
                }else{
                    [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[productName]];
                }
                
                [tableView reloadSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
            }
 
        }
            break;
        case 2:
        {
            
        }
            break;
        case 3:
        {
            LKWorkOrderListDetailCell *cell = [tableView cellForRowAtIndexPath:indexPath];
            //回款账户
            NSString *repayAccountCode = [NSString stringWithFormat:@"%@%@",@"回款账户卡号：",_model.repayAccountCode];
            NSString *repayAccountName = [NSString stringWithFormat:@"%@%@",@"用户名：",_model.repayAccountName];

            NSString *repayBankName = [NSString stringWithFormat:@"%@%@",@"开户行：",_model.repayBankName];
            NSString *repayBankBranch = [NSString stringWithFormat:@"%@%@",@"开户行支行：",_model.repayBankBranch];
            NSString *repayBankCity = [NSString stringWithFormat:@"%@%@",@"开户行支行省市：",_model.repayBankCity];
            NSString *repayBankImageUrl = [NSString stringWithFormat:@"%@%@",@"银行卡正面复印件：",_model.repayAccountPhotoUrl];
            //划扣账户
            NSString *payAccountCode = [NSString stringWithFormat:@"%@%@",@"划扣账户卡号：",_model.payAccountCode];
            NSString *payAccountName = [NSString stringWithFormat:@"%@%@",@"用户名：",_model.payAccountName];
            NSString *payBankName = [NSString stringWithFormat:@"%@%@",@"开户行：",_model.payBankName];
            NSString *payBankBranch = [NSString stringWithFormat:@"%@%@",@"开户行支行：",_model.payBankBranch];
            NSString *payBankCity = [NSString stringWithFormat:@"%@%@",@"开户行支行省市：",_model.payBankCity];
            NSString *payBankImageUrl  = [NSString stringWithFormat:@"%@%@",@"银行卡正面复印件：",_model.payAccountPhotoUrl];
            if (cell.arrowBtn.hidden == NO) {
                if (indexPath.row == 0) {
                    self.bankFlag = !self.bankFlag;
                    cell.arrowBtn.selected = self.bankFlag;
                }else{
                    self.secondbankFlag = !self.secondbankFlag;
                    cell.arrowBtn.selected = self.secondbankFlag;
                        
                }
                if (self.secondbankFlag && self.bankFlag) {
                    if ([self.model.identitfyCategory isEqual:@"1"]) {
                        if ([self.model.cusIsAuthenticated boolValue]) {
                        [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity]];
                        }else{
                            
                          [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,@"银行卡正面复印件：",repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity,@"银行卡正面复印件："]];
                        }

                    }else{
                        [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,@"银行卡正面复印件：",repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity,@"银行卡正面复印件："]];
                    }

                }else if(self.secondbankFlag && !self.bankFlag){
                    if ([self.model.identitfyCategory isEqual:@"1"]) {
                        if ([self.model.cusIsAuthenticated boolValue]) {
                            [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity]];

                        }else{
                           [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity,@"银行卡正面复印件："]];
                        }
                    }else{
                        [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,repayAccountCode,repayAccountName,repayBankName,repayBankBranch,repayBankCity,@"银行卡正面复印件："]];
                    }

                }else if (!self.secondbankFlag && self.bankFlag){
                    if ([self.model.identitfyCategory isEqual:@"1"]) {
                        if ([self.model.cusIsAuthenticated boolValue]) {
                            [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,repayAccountCode]];
                        }else{
                            [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,@"银行卡正面复印件：",repayAccountCode]];
                        }
 
                    }else{
                     [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,payAccountName,payBankName,payBankBranch,payBankCity,@"银行卡正面复印件：",repayAccountCode]];
                    }

                }else{
                    [_cellContentArray replaceObjectAtIndex:indexPath.section withObject:@[payAccountCode,repayAccountCode]];
                }
                [tableView reloadSection:indexPath.section withRowAnimation:UITableViewRowAnimationNone];
            }
 
        }
            break;
        case 4:
        {
            
        }
            break;
        case 5:
        {
            
        }
            break;
        case 6:
        {
            if (indexPath.row == 0) {
                self.contractHomeFlag = !self.contractHomeFlag;
            }else if (indexPath.row == 1){
                self.contractDetailFlag = !self.contractDetailFlag;
            }else if (indexPath.row == 2){
                self.POSFlag = !self.POSFlag;
            }else{
                self.otherFlag = !self.otherFlag;
            }
            [self.tableview reloadRowAtIndexPath:indexPath withRowAnimation:UITableViewRowAnimationNone];
        }
            break;
        default:
            break;
    }
}

-(NSArray *)headerTitlsArray{
    if (!_headerTitlsArray) {
        _headerTitlsArray = @[@"客户信息",@"产品信息",@"协议信息",@"银行信息",@"优惠券",@"订单来源",@"附件信息"];
    }
    return _headerTitlsArray;
}
-(NSArray *)headerIconsArray{
    if (!_headerIconsArray) {
        _headerIconsArray = @[@"kehuxinxi",@"kehuxinxi",@"xieyixinxi",@"yinhangxinxi",@"youhuiquan",@"dingdanaiyuan",@"fujian"];
    }
    return _headerIconsArray;
}
-(NSMutableArray *)cellContentArray{
    if (!_cellContentArray) {
        _cellContentArray = [[NSMutableArray alloc] init];
    }
    return _cellContentArray;
}
/**
 从相册或者相机中选择图片
 
 @param alert 弹框
 @param sourceTypea 相机或者相册
 */
-(void)camerOrAlbumsPhotoChooseWithAlert:(UIAlertController *)alert AndSourceType:(NSInteger) sourceTypea{
    __block NSInteger sourceType = sourceTypea;
    [alert addAction:[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //来源:相机
        sourceType = UIImagePickerControllerSourceTypeCamera;
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = (id)self;
        imagePickerController.allowsEditing = NO;
        imagePickerController.sourceType = sourceType;
        imagePickerController.transitioningDelegate = self;
        imagePickerController.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:imagePickerController animated:YES completion:nil];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        //来源:相册
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = (id)self;
        imagePickerController.allowsEditing = NO;
        imagePickerController.navigationBar.translucent = NO;
        [imagePickerController.navigationBar setBarTintColor:blueDefault];
        imagePickerController.sourceType = sourceType;
        imagePickerController.transitioningDelegate = self;
        imagePickerController.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:imagePickerController animated:YES completion:nil];
        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
}
#pragma mark - 调用相机的代理方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    UIImage *aimage = image;
    self.currentImageView.image = aimage;
    
}
//缩放图片到指定大小的imageview
- (UIImage*)imageCompressWithSimple:(UIImage*)image scaledToSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [image drawInRect:CGRectMake(0,0,size.width,size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

/**
 获取订单的详细信息
 */
-(void)getOrderDetailInformaiton{
    [SVProgressHUD showWithStatus:@"加载中..."];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:orderDetailInforUrl header:[LKUserInforTool header] parameters:@{@"Id":_model.orderId} progress:^(NSProgress * _Nullable progress) {

    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD dismiss];
        LKOrderModel *model = [LKOrderModel modelWithDictionary:responseObject[@"result"]];
        _model = model;
        //客户信息
        NSString *customerName = [NSString stringWithFormat:@"%@%@",@"客户名称：",_model.customerName];
        NSString *customerCode = [NSString stringWithFormat:@"%@%@",@"客户编号：",_model.customerCode];
        NSString *identCatoType = [NSString stringWithFormat:@"证件类型：%@",[NSString backTitleAccordingIdCatogaryType:[_model.identitfyCategory integerValue]]];
        NSString *identId = [NSString stringWithFormat:@"%@%@",@"证件号码：",_model.identityId];
        NSString *Adress = [NSString stringWithFormat:@"%@%@",@"通讯地址：",[NSString judegeIsNullAndTransform:_model.address]];
        
        //订单来源信息
        NSString *orderOwner = [NSString stringWithFormat:@"%@%@",@"订单所属人：",_model.ownerName];
        NSString *areaZongStr = _model.area == nil ? @"":_model.area;
        NSString *areaZong = [NSString stringWithFormat:@"%@%@",@"所属区总：",areaZongStr];
        
        NSString *fenZong = [NSString stringWithFormat:@"%@%@",@"所属分总：",[NSString judegeIsNullAndTransform:_model.branchCompany]];
        NSString *laoZong = [NSString stringWithFormat:@"%@%@",@"所属总监：", [NSString judegeIsNullAndTransform:_model.salesDepartment]];
       
        NSString *director = [NSString stringWithFormat:@"%@%@",@"所属主管：",[NSString judegeIsNullAndTransform:_model.director]];
        
        //协议信息
        NSString *contractCode = [NSString stringWithFormat:@"%@%@",@"合同编号：",_model.contractCode];
        NSString *investMoney = [NSString stringWithFormat:@"%@%@",@"投资金额：",_model.investmentAmount];
        NSString *fujialiLv = [NSString stringWithFormat:@"%@%@",@"附加利率：",_model.additionalInterestRate];
        NSString *qixiDate = [NSString stringWithFormat:@"%@%@",@"起息日期：",[[_model.calulationDate componentsSeparatedByString:@"T"] firstObject]];
        NSString *daoqiDate = [NSString stringWithFormat:@"%@%@",@"到期日期：",_model.enExpireDateTest];
        NSString *payType = [NSString stringWithFormat:@"%@%@",@"支付方式：",[self accordingPayType:[_model.paymentCategory integerValue]]];
        NSString *tradeCode = [NSString stringWithFormat:@"%@%@",@"交易参考号：",_model.transactionReferenceNumber];
        NSString *posCode = [NSString stringWithFormat:@"%@%@",@"POS机终端号：",_model.posCode];
        NSString *suppelmentStr = _model.supplement == nil ? @"":_model.supplement;
        NSString *suppelment = [NSString stringWithFormat:@"%@%@",@"附加说明：",suppelmentStr];
        //产品信息
        NSString *productName = [NSString stringWithFormat:@"%@%@",@"产品名称：",_model.productName];
        //银行卡信息
        //回款账户
        NSString *repayAccountCode = [NSString stringWithFormat:@"%@%@",@"回款账户卡号：",_model.repayAccountCode];
        //回款账户
        NSString *payAccountCode = [NSString stringWithFormat:@"%@%@",@"划扣账户卡号：",_model.payAccountCode];
        NSMutableArray *voucherArra = [[NSMutableArray alloc] init];
        for (NSDictionary *dic in _model.orderVoucher) {
            YLInvestmentCertificateModel *model = [YLInvestmentCertificateModel modelWithDictionary:dic];
            [voucherArra addObject:model];
        }
        
        if ([self.model.isContinuedInvestment integerValue]) {
            NSString *previesCode = [NSString stringWithFormat:@"原合同编号：%@",_model.previousContractCode];
            NSString *previesMoney = [NSString stringWithFormat:@"原合同金额：%@",_model.previousOrderInvestmentAmount];
            NSString *conitnueInvestMoney = [NSString stringWithFormat:@"追加金额：%@",_model.continueInvestmentAmount];
            if ([self.model.identitfyCategory isEqual:@"1"]) {
                if ([self.model.cusIsAuthenticated boolValue]) {
                self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress],@[productName],@[previesCode,contractCode,previesMoney,conitnueInvestMoney,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
                }else{
                    self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress,@"证件正面：",@"证件背面："],@[productName],@[previesCode,contractCode,previesMoney,conitnueInvestMoney,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
                }

            }else{
                self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress,@"证件正面：",@"证件背面："],@[productName],@[previesCode,contractCode,previesMoney,conitnueInvestMoney,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
            }

        }else{
            if ([self.model.identitfyCategory isEqual:@"1"]) {
                if ([self.model.cusIsAuthenticated boolValue]) {
                    self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress],@[productName],@[contractCode,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
                }else{
                    self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress,@"证件正面：",@"证件背面："],@[productName],@[contractCode,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
                }

            }else{
                    self.cellContentArray = [NSMutableArray arrayWithArray:@[@[customerName,customerCode,identCatoType,identId,Adress,@"证件正面：",@"证件背面："],@[productName],@[contractCode,investMoney,fujialiLv,qixiDate,daoqiDate,payType,tradeCode,posCode,suppelment],@[payAccountCode,repayAccountCode],@[],@[orderOwner,director,laoZong,fenZong,areaZong],@[@"合同首页",@"合同详情",@"POS凭证",@"其他"]]];
            }

        }

        [self.tableview reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

/**
 根据支付方式类型返回支付方式

 @param type 类型
 @return 支付方式
 */
-(NSString *)accordingPayType:(NSInteger)type{
    if (type == 1) {
        return @"POS终端";
    }else{
        return @"转账";
    }
}

/**
 根据兑付方式返回兑付类型

 @param type 兑付方式
 @return 兑付类型
 */
-(NSString *)accordingDuiFuFangshiType:(NSInteger)type{
    if (type == 0) {
        return @"到期分配";
    }else if(type == 1){
        return @"按月分配";
    }
    return @"半年分配";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
